home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C12 / Opconv.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  492 b   |  28 lines

  1. //: C12:Opconv.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Op overloading conversion
  7.  
  8. class Three {
  9.   int i;
  10. public:
  11.   Three(int ii = 0, int = 0) : i(ii) {}
  12. };
  13.  
  14. class Four {
  15.   int x;
  16. public:
  17.   Four(int xx) : x(xx) {}
  18.   operator Three() const { return Three(x); }
  19. };
  20.  
  21. void g(Three) {}
  22.  
  23. int main() {
  24.   Four four(1);
  25.   g(four);
  26.   g(1);  // Calls Three(1,0)
  27. } ///:~
  28.